package com.ttbj.core.util.security;

import java.security.MessageDigest;

/**
 * MD5工具类
 * 
 * @date 2014-2-13 下午01:25:50
 * @author Daniel
 */
public class Md5 {

    public static String digist(String text) {
        String result = "";

        try {
            MessageDigest md = MessageDigest.getInstance("md5");
            // 定义编码方式
            byte[] bufs = text.getBytes("UTF-8");
            md.update(bufs);
            byte[] b = md.digest();
            int i;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0) {
                    i += 256;
                }
                if (i < 16) {
                    buf.append("0");
                }
                buf.append(Integer.toHexString(i));
            }
            result = buf.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
